package com.ymatou.operate.trading.api.testcase;

import java.util.HashMap;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.operate.trading.api.parameter.CreateOrderHistoryBean;
import com.ymatou.operate.trading.api.service.CreateOrderHistoryCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.utils.constant.ECode;

/**
 * 创建订单流水信息 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_CreateOrderHistory {
	private static CreateOrderHistoryBean cohbean;
	private static CreateOrderHistoryCall cohcall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("创建订单流水信息");
	}

	@Before
	public void caseUp() {

		cohbean = new CreateOrderHistoryBean();
		cohcall = new CreateOrderHistoryCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(cohcall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	//该接口即将废弃
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CreateOrderHistory_001() {
		Logger.start(true,"创建订单流水信息成功");
		try {
			// 创建订单
			PlaceOrderResp placeOrderResp=new OrderCallService().createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId =placeOrderResp.getOrderList().get(0).getSellerId();
			int userId =placeOrderResp.getUserId();         
			int tradingId = placeOrderResp.getTradingId();

			// 查询操作前记录条数
			DefaultWapper database = new DefaultWapper();
			HashMap<String, Integer> m = new HashMap<String, Integer>();
			m.put("TraddingId", orderId);
			int num1 = database.selectTradingStatus(m).size();
			// 参数
			String memo = "自动化创建流水信息";
			cohbean.setMemo(memo);
			cohbean.setOrderId(orderId);
			// 发送请求
			cohcall.setData(cohbean);
			cohcall.callService();
			Logger.comment("cohcall send:" + cohcall.getEntityString());
			Logger.comment("cohcall response:" + cohcall.getReturnData());
			Logger.verifyEquals(ECode.SUCCESS, cohcall.getCode(), "验证Code");
			// Logger.verifyEquals(ErrorCode.SUCCESSMSG, cohcall.getMsg(),
			// "验证Msg");
			// 数据库验证
			int num2 = database.selectTradingStatus(m).size();// 操作后记录条数
			Logger.verifyEquals(1, num2 - num1, "验证交易信息表增加一条记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}